<script setup lang="ts">
import { useOperator } from "./hook";
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";

defineOptions({
  name: "OperateLog",
});

const {
  form,
  formRef,
  loading,
  columns,
  dataList,
  pagination,
  onSearch,
  resetForm,
  handleSizeChange,
  handleCurrentChange,
} = useOperator();
</script>

<template>
  <div class="main">
    <el-form
      ref="formRef"
      :inline="true"
      :model="form"
      class="bg-bg_color w-[99/100] pl-8 pt-4"
    >
      <el-form-item label="请求ID" prop="id">
        <el-input
          v-model="form.id"
          key="form.id"
          placeholder="请输入请求名称"
          clearable
          class="!w-[200px]"
        />
      </el-form-item>
      <el-form-item label="业务名称" prop="busType">
        <el-input
          v-model="form.busType"
          key="form.busType"
          placeholder="请输入业务名称"
          clearable
          class="!w-[200px]"
        />
      </el-form-item>
      <el-form-item label="接口名称" prop="title">
        <el-input
          v-model="form.title"
          key="form.title"
          placeholder="请输入接口名称"
          clearable
          class="!w-[200px]"
        />
      </el-form-item>
      <el-form-item label="IP地址" prop="remoteAddr">
        <el-input
          v-model="form.remoteAddr"
          key="form.remoteAddr"
          placeholder="请输入IP地址"
          clearable
          class="!w-[180px]"
        />
      </el-form-item>
      <el-form-item label="请求结果" prop="status">
        <el-select
          v-model="form.status"
          key="form.status"
          placeholder="请选择请求结果"
          clearable
          class="!w-[180px]"
        >
          <el-option label="成功" value="成功" />
          <el-option label="失败" value="失败" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          :icon="useRenderIcon('ep:search')"
          :loading="loading"
          @click="onSearch"
        >
          搜索
        </el-button>
        <el-button
          :icon="useRenderIcon('ep:refresh')"
          @click="resetForm(formRef)"
        >
          重置
        </el-button>
      </el-form-item>
    </el-form>

    <PureTableBar title="日志列表" @refresh="onSearch">
      <template #buttons />
      <template v-slot="{ size, checkList }">
        <pure-table
          border
          align-whole="center"
          showOverflowTooltip
          table-layout="auto"
          :loading="loading"
          :size="size"
          :data="dataList"
          :columns="columns"
          :checkList="checkList"
          :pagination="pagination"
          :paginationSmall="size === 'small' ? true : false"
          :header-cell-style="{
            background: 'var(--el-table-row-hover-bg-color)',
            color: 'var(--el-text-color-primary)',
          }"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </template>
    </PureTableBar>
  </div>
</template>

<style scoped lang="scss">
:deep(.el-dropdown-menu__item i) {
  margin: 0;
}
</style>
